package com.atguigu.bigdata.scala.mytest.chapter07

object Test_Method {
  def main(args: Array[String]): Unit = {
    val ints: List[Int] = List(1,2,3,4)

    //集合映射,返回操作后的结果
    val ints1: List[Int] = ints.map(s => s * 2)
    println(ints1)//List(2, 4, 6, 8)

    //集合过滤,返回符合过滤条件的集合,返回过滤后的结果
    val ints3: List[Int] = ints.filter(p => p%2==0)
    println(ints3)//List(2, 4)

    //分组,根据函数分组
    val booleanToInts: Map[Int, List[Int]] = ints.groupBy(p => p%2)
    println(booleanToInts)//Map(1 -> List(1, 3), 0 -> List(2, 4))

    val list: List[List[Int]] = List(
      List(1, 2), List(3, 4)
    )

    //集合扁平化
    val flatten: List[Int] = list.flatten
    println(flatten)//List(1, 2, 3, 4)

    //集合扁平映射 将List(1, 2)传递给list.map(s=>s+1)
    val ints2: List[Int] = list.flatMap(list=>list.map(s=>s+1))
    println(ints2)//List(2, 3, 4, 5)

    val list1: List[List[Int]] = list.map(a=>a.map(b=>b+1))
    val flatten1: List[Int] = list1.flatten
    println(flatten1)//List(2, 3, 4, 5)

  }
}
